package com.whsxt.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
//import com.alipay.demo.trade.config.Configs;
//import com.alipay.demo.trade.service.AlipayTradeService;
//import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-03-30 10:48
 * @Description:
 */
@Configuration
@EnableConfigurationProperties(value = AliPayProperties.class)
public class AliPayAutoConfiguration {

    @Autowired
    private AliPayProperties aliPayProperties;


//    public AliPayAutoConfiguration() {
//        //在构造方法里可以加载配置文件
//        Configs.init("zfbinfo.properties");
//    }



//    @Bean
//    public AlipayTradeService alipayTradeService(){
//        return new AlipayTradeServiceImpl.ClientBuilder().build();
//    }


    /**
     * 需要在容器中放一个alipay客户端
     *
     * @return
     */
    @Bean
    public AlipayClient alipayClient() {
        return new DefaultAlipayClient(aliPayProperties.getGatewayUrl(),
                aliPayProperties.getAppId(),
                aliPayProperties.getMerchantPrivateKey(),
                "json", "UTF-8",
                aliPayProperties.getAlipayPublicKey(),
                aliPayProperties.getSignType());
    }
}
